package com.app.megaprosoft.modyimcarcare;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;

import com.itextpdf.text.Element;
import com.megaprosoft.modyimcarcare.R;



import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class HoleActivity extends Activity {
	
	connect con = new connect(); 
	DecimalFormat df = new DecimalFormat("#,###,##0.00");	
	ResultSet rs;
	TextView	TextSum,et1,et2,et3,et4,et5,et6,et7,et8,et9,et10,et11,et12,et13,et14,et15,et16,et17,SumAmount;
	CheckBox 	c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17
				,checkVIP,checkDis;
	double a,b,c,d,e,f,g,h,ii,j,k,l,m,n,o,p,q,r,subSum = 0,finalSum = 0,amount = 0 ;
	int timeSum = 0;
	ResultSet rs2;
	EditText	disc,prom,disBTH;
	Button 		btn1,btn2,Sum,addService;
	String list1="",list2="",list3="",list4="",list5="",list6="",list7="",list8="",list9="",
			list10="",list11="",list12="",list13="",list14="",list15="",list16="",list17="";
	
	EditText orther1,orther2,orther3;
	Spinner spnDis;
	String checkOrther1 = "";
	
    private int mYear;
    private int mMonth;
    private int mDay;
	String NameInput,company,OID;
    String div1,div2,div3,div4,div5,div6,div7,div8,div9,div10,div11,div12,div13,div14,div15;
	String price1="",price2="",price3="",price4="",price5="",price6="",price7="",price8="",price9="",
			price10="",price11="",price12="",price13="",price14="",price15="",price16="",price17="";
	
	int t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14;

	String ServiceID,DisCt,sumDiscNull,sumDisBTHNull,VIPcode,addHole;
	String str1,str2,str3,str9,str10,str11 ;
	
	ArrayList<String> price = new ArrayList<String>();
	ArrayList<String> name = new ArrayList<String>();
	ArrayList<String> time = new ArrayList<String>();
	
	ArrayList<String> Gearprice = new ArrayList<String>();
	ArrayList<String> Gearname = new ArrayList<String>();
	ArrayList<String> Geartime = new ArrayList<String>();
	
	ArrayList<String> Sprocketsprice = new ArrayList<String>();
	ArrayList<String> Sprocketsname = new ArrayList<String>();
	ArrayList<String> Sprocketstime = new ArrayList<String>();
	
	
	ArrayList<String> GearOilAutoprice = new ArrayList<String>();
	ArrayList<String> GearOilAutoname = new ArrayList<String>();
	ArrayList<String> GearOilAutotime = new ArrayList<String>();

	ArrayList<String> SteeringWheelprice = new ArrayList<String>();
	ArrayList<String> SteeringWheelname = new ArrayList<String>();
	ArrayList<String> SteeringWheeltime = new ArrayList<String>();
	
	ArrayList<String> withinprice = new ArrayList<String>();
	ArrayList<String> withinname = new ArrayList<String>();
	ArrayList<String> withintime = new ArrayList<String>();
	
    ArrayList<String> boilerprice = new ArrayList<String>();
	ArrayList<String> boilername = new ArrayList<String>();
	ArrayList<String> boilertime = new ArrayList<String>();
	
	ArrayList<String> liquorprice = new ArrayList<String>();
	ArrayList<String> liquorname = new ArrayList<String>();
	ArrayList<String> liquortime = new ArrayList<String>();
	
	ArrayList<String> Brakesprice = new ArrayList<String>();
	ArrayList<String> Brakesname = new ArrayList<String>();
	ArrayList<String> Brakestime = new ArrayList<String>();
	
	ArrayList<String> filterprice = new ArrayList<String>();
	ArrayList<String> filtername = new ArrayList<String>();
	ArrayList<String> filtertime = new ArrayList<String>();
	
	ArrayList<String> filterAirprice = new ArrayList<String>();
	ArrayList<String> filterAirname = new ArrayList<String>();
	ArrayList<String> filterAirtime = new ArrayList<String>();
	                 
	
	ArrayList<String> amountOne = new ArrayList<String>();
	ArrayList<String> amountGear = new ArrayList<String>();
	ArrayList<String> amountSprockets = new ArrayList<String>();

	
	
	
	ArrayList<String> amountGearOilAuto = new ArrayList<String>();
	ArrayList<String> amountSteeringWheel = new ArrayList<String>();
	ArrayList<String> amountwithin = new ArrayList<String>();
	ArrayList<String> amountboiler= new ArrayList<String>();
	ArrayList<String> amountgrease= new ArrayList<String>();
	
	ArrayList<String> amountBrakes = new ArrayList<String>();
	ArrayList<String> amountfilter = new ArrayList<String>();
	ArrayList<String> amountfilterAir = new ArrayList<String>();
	
	ArrayList<String> amountliquor= new ArrayList<String>();
	ArrayList<String> amountcompress= new ArrayList<String>();
	ArrayList<String> amountcolor= new ArrayList<String>();
	
	ArrayList<String> Dis = new ArrayList<String>();
	
	public static int CHECH_orther1 = 0; 
	public static int CHECH_orther2 = 0; 
	public static int CHECH_orther3 = 0; 
	public static boolean CHECH_ADD = true; 
	public static final int REQUEST_CODE = 1;  
	
	String[] arr ;
	String[] arr2;
	
	String timeSer,sumSer,listSer,priceSer,sumDisc,sumDisBTH ;
	
	AutoCompleteTextView textmotorOil;
	AutoCompleteTextView textGearOil;
	AutoCompleteTextView textSprocketsOil;
	
	AutoCompleteTextView textGearOilAuto;
	AutoCompleteTextView textSteeringWheel;
	AutoCompleteTextView textwithin;
	AutoCompleteTextView  textboiler;
	AutoCompleteTextView textbrake;
	AutoCompleteTextView textfilter;
	AutoCompleteTextView textliquor;
	AutoCompleteTextView textfilterAir;
	
	String TypeID,RegisterIDS;
	
	boolean check=true;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.activity_hole);
		
		
		
		 disc = (EditText) findViewById(R.id.discount);
		 
		 TextSum = (TextView) findViewById(R.id.Sum);
		 Sum = (Button) findViewById(R.id.ButtonSum);
		 
		 btn1 = (Button) findViewById(R.id.button1);
		 btn2 = (Button) findViewById(R.id.button2);
		 
		 
		 addHole = getIntent().getExtras().getString("addHole");
		 NameInput = getIntent().getExtras().getString("name");
		 company = getIntent().getExtras().getString("CompanyS");
		 OID = getIntent().getExtras().getString("OID");
		 TypeID = getIntent().getExtras().getString("TypeID");
	     RegisterIDS = getIntent().getExtras().getString("RegisterIDS");
		 
	     addService = (Button) findViewById(R.id.addList);
		 //RegisterIDS = "9999";
		 
		 textmotorOil = (AutoCompleteTextView) findViewById(R.id.Months);
		 textmotorOil.setEnabled(false);
		 textGearOil = (AutoCompleteTextView) findViewById(R.id.Auto2);
		 textGearOil.setEnabled(false);
		 textSprocketsOil = (AutoCompleteTextView) findViewById(R.id.Auto3);
		 textSprocketsOil.setEnabled(false);
		 
		 
		 textGearOilAuto = (AutoCompleteTextView) findViewById(R.id.Auto4);
		 textGearOilAuto.setEnabled(false);
		 
		 textSteeringWheel = (AutoCompleteTextView) findViewById(R.id.Auto5);
		 textSteeringWheel.setEnabled(false);
		 
		 textwithin = (AutoCompleteTextView) findViewById(R.id.Auto6);
		 textwithin.setEnabled(false);
		 
		 textboiler = (AutoCompleteTextView) findViewById(R.id.Auto7);
		 textboiler.setEnabled(false);
		 
		 textliquor = (AutoCompleteTextView) findViewById(R.id.Auto12);
		 textliquor.setEnabled(false);
		 
		 
		 textbrake = (AutoCompleteTextView) findViewById(R.id.Auto9);
		 textbrake.setEnabled(false);
		 textfilter = (AutoCompleteTextView) findViewById(R.id.Auto10);
		 textfilter.setEnabled(false);
		 textfilterAir = (AutoCompleteTextView) findViewById(R.id.Auto11);
		 textfilterAir.setEnabled(false);
		 
		 
		
		
		 
		 checkVIP = ( CheckBox ) this.findViewById ( R.id.checkVIP );
		 checkDis = ( CheckBox ) this.findViewById ( R.id.checkDis );
		 disc = (EditText) findViewById(R.id.discount);
		 disBTH = (EditText) findViewById(R.id.disBTH);
		 SumAmount = ( TextView ) this.findViewById ( R.id.SumAmount );
		 
		 sumDisc = "0";
	 	 sumDisBTH = "0";
	 	 
	 	 prom = (EditText) findViewById(R.id.VIPcode);	
	 	 
	 	disc.setEnabled(false);
		disBTH.setEnabled(false);
		prom.setEnabled(false);	
		 
		 
		motorOil();
		GearOil();
		SprocketsOil();
		GearOilAuto();
		SteeringWheel();
		within();
		boiler();
		grease();
		brake();
		filter();
		filterAir();
		liquor();
		compress();
		color();
		
		orther1(); 
		orther2(); 
		orther3(); 
			
		
				////////////////////////////Discount //////////////////////////////////	
		
		if(addHole.equals("addHole")){
			
			checkDis.setEnabled(false);
			checkVIP.setEnabled(false);
			addService.setEnabled(false);
			c15.setEnabled(false);
			c16.setEnabled(false); 
			c17.setEnabled(false);
			
			
			
		}else{
				checkDis.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					if(checkDis.isChecked()){
				
						selectDis();
					
						disc.setEnabled(true);
						disBTH.setEnabled(true);
						spnDis.setEnabled(true);		    				
					
						}
					else {
						
						disc.setEnabled(false);
						disBTH.setEnabled(false);
						sumDisc = "0";
						sumDisBTH = "0";
						disc.setText("0");
						disBTH.setText("0");
						Dis.clear();
						spnDis.setEnabled(false);
						
					
						
						}
					
				
				}
				});
				
				
				
				
				/////////////////////////////// Check VIP   ///////////////////////////
				
				checkVIP.setOnClickListener(new View.OnClickListener() {
					//String str;
					@Override
					public void onClick(View v) {
						if(checkVIP.isChecked()){
							
							
							 prom.setEnabled(true);	 
							 disc.setEnabled(true);
							 disBTH.setEnabled(true);
				
							
							}
						else {
							
				
							prom.setEnabled(false);	 
							disc.setEnabled(false);
							disBTH.setEnabled(false);
							
							sumDisc = "0";
							sumDisBTH = "0";
							disc.setText("0");
							disBTH.setText("0");
							
							 	prom.setText("");
							 	
							
						    
							
							
							}
						
					
				   }
				});	
				
				
				
		}	
		
		

		
		addService.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				
				CHECH_ADD = false;
				Intent intent = new Intent(HoleActivity.this, services.class);		
				intent.putExtra("name", NameInput);
				intent.putExtra("CompanyS", company);
				intent.putExtra("addSer", "addSer");
				intent.putExtra("OID", OID);
				intent.putExtra("TypeID", TypeID);
				intent.putExtra("RegisterIDS", RegisterIDS);
				startActivityForResult(intent, REQUEST_CODE); 
			
				
			}
			});
		
		
		btn2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				//Open Form Add
				btn2.setBackgroundColor(Color.GREEN);
				Intent newActivityAdd = new Intent(HoleActivity.this,InitialServices.class);
				newActivityAdd.putExtra("name", NameInput);
				newActivityAdd.putExtra("CompanyS", company);
				
				startActivity(newActivityAdd);

			}
			});
				///////////////////// sum  ////////////////////////////////
		
		
		Sum.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				
				
				
				
				if(et15.getText().toString().equals("")){
					p = 0;
				}else{
				p = Double.parseDouble(et15.getText().toString());
				}
				
				if(et16.getText().toString().equals("")){
					q = 0;
				}else{
				q = Double.parseDouble(et16.getText().toString());
				}
				
				if(et17.getText().toString().equals("")){
					r = 0;
				}else{
				r = Double.parseDouble(et17.getText().toString());
				}
				
				
				
				///////////  ��ǹ ����� ////////////
				
				if(et15.getText().toString().equals("")){
					p = 0;
				}else{
				p = Double.parseDouble(et15.getText().toString());
				}
				
				if(et16.getText().toString().equals("")){
					q = 0;
				}else{
				q = Double.parseDouble(et16.getText().toString());
				}
				
				if(et17.getText().toString().equals("")){
					r = 0;
				}else{
				r = Double.parseDouble(et17.getText().toString());
				}
				
				
						//////////////  ��ǹŴ�ٻͧ	
							sumDiscNull = disc.getText().toString();
		    				
		    				if(sumDiscNull.equals(null)||sumDiscNull.equals("")){
		    					sumDisc = "0";
		    				}else{
		    					sumDisc = sumDiscNull;
		    				}
		    				sumDisBTHNull = disBTH.getText().toString();
		    				
		    				if(sumDisBTHNull.equals(null)||sumDisBTHNull.equals("")){
		    					sumDisBTH = "0";
		    				}else{
		    					
		    					sumDisBTH = sumDisBTHNull;
		    				}
		    				
		    			////////////////���ǹŴ VIP
		    				VIPcode = prom.getText().toString();

				
				
			
				
				
				
				
				timeSum = t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14;
				timeSum = timeSum+0;
				Toast.makeText(HoleActivity.this, "All time is : "+timeSum, Toast.LENGTH_SHORT).show();
				
				amount = a+b+c+d+e+f+g+h+ii+j+k+l+m+n+o+p+q+r;
				SumAmount.setText(String.valueOf(df.format(amount)));
				
				finalSum = (amount-Integer.parseInt(sumDisBTH))-(((amount-Integer.parseInt(sumDisBTH))*Integer.parseInt(sumDisc))/100);
				

				TextSum.setText(String.valueOf(df.format(finalSum)));	

			}
			});
		
		
		
		final Calendar c = Calendar.getInstance();
		
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH); 
		 
		 btn1.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					
	if(services.CHECH_ADD){				
					rs2 = con.selectData("SELECT MAX(ServiceID) AS maxid FROM CustomerCar WHERE RegisterID = '"+RegisterIDS+"' ");
   				try {
   					rs2.next();
   					ServiceID = rs2.getString("maxid");
   				} catch (SQLException e1) {
   					// TODO Auto-generated catch block
   					e1.printStackTrace();
   				}
   				
   				if(et15.getText().toString().equals("")){
   					price15 = "-,";
	   				list15 = "-,";
				}else{
					price15 = et15.getText().toString()+",";
	   				list15 = orther1.getText().toString()+",";
				}
				
				if(et16.getText().toString().equals("")){
					price16 = "-,";
	   				list16 = "-,";
				}else{
					price16 = et16.getText().toString()+",";
	   				list16 = orther2.getText().toString()+",";
				}
				
				if(et17.getText().toString().equals("")){
					price17 = "-,";
	   				list17 = "-,";
				}else{
					price17 = et17.getText().toString()+",";
	   				list17 = orther3.getText().toString()+",";
				}
   				
   				
   				
   			
   				
   				
					 
				String sql = "INSERT INTO DataService " +
						"(ServiceID,TypeID,List,price,VIPcode,Discount,amount,Sum,sumTime,date" +
						",DiscountName,PriceBTH,checkOrther) " +
						"VALUES ("+
						"'"+ServiceID+"'" + ',' + 
						"'"+TypeID+"'" + ',' + 
						"'"+list1+list2+list3+list4+list5+list6+list7+list8+list9+
						list10+list11+list12+list13+list14+list15+list16+list17+"'" + ',' + 
						"'"+price1+price2+price3+price4+price5+price6+price7+price8+price9+
						price10+price11+price12+price13+price14+price15+price16+price17+"'" + ',' + 
						"'"+VIPcode+"'" + ',' +
									"'"+sumDisc+"'" + ',' +
									"'"+amount+"'" + ',' +
									"'"+finalSum+"'" + ',' +
									"'"+timeSum+"'" + ',' +
							        "'"+mDay+"/"+(1+mMonth)+"/"+mYear+"'" + "," +
							        "'"+DisCt+"'" + ',' +
							          "'"+sumDisBTH+"'" + ',' +
								   "'"+checkOrther1+"'" + ") "; 
				
   				
   				Log.i("list10",""+list10);
   				Log.i("list11",""+list11);
					
				if(con.addData(sql)){	 
				Toast.makeText(HoleActivity.this, "Inserted data successfully", Toast.LENGTH_SHORT).show();
			
				Toast.makeText(HoleActivity.this, ServiceID, Toast.LENGTH_SHORT).show();
				Intent newActivityAdd = new Intent(HoleActivity.this,Card.class);
				newActivityAdd.putExtra("ServiceID", ServiceID);
				newActivityAdd.putExtra("name", NameInput);
				newActivityAdd.putExtra("CompanyS", company);
				startActivity(newActivityAdd);
				
				}else{
			    Toast.makeText(HoleActivity.this, "Inserted data fail", Toast.LENGTH_SHORT).show();
			  
				}
				
				}else{
				
					
					services.CHECH_ADD = true;
					  Toast.makeText(HoleActivity.this, "���������", Toast.LENGTH_SHORT).show();
					  Intent i = new Intent();
						i.putExtra("time", timeSum+"");
						i.putExtra("Money", finalSum+"");
						i.putExtra("list", list1+list2+list3+list4+list5+list6+list7+list8+list9+
								list10+list11+list12+list13+list14);
						i.putExtra("price", price1+price2+price3+price4+price5+price6+price7+price8+price9+
								price10+price11+price12+price13+price14);
						i.putExtra("name", NameInput);
						i.putExtra("CompanyS", company);
						setResult(services.REQUEST_CODE, i);
					    finish();
					   
				}
				}
		 });
		 
	}
	
	
	
	private void motorOil() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin1);
		 spn.setEnabled(false);
	
		 c1 = ( CheckBox ) this.findViewById ( R.id.check1);			
		 et1 = ( TextView ) this.findViewById ( R.id.result1);
	

		 c1.setOnClickListener(new View.OnClickListener() {
			
				@Override
				public void onClick(View v) {
	    			if(c1.isChecked()){
	    				spn.setEnabled(true);
	    				textmotorOil.setEnabled(true);
						 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201309160001' ");		   

									try {
										while(rs.next()){          
											price.add(rs.getString("LastBuyPrice"));	
											name.add(rs.getString("ItemName"));	
											time.add(rs.getString("Duration"));
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}    
									
									for(int i = 1 ; i<=10 ; i++){
										amountOne.add(String.valueOf(i));
										}
									
									
									
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, name);
									textmotorOil.setThreshold(1);
							         
									textmotorOil.setAdapter(adapter);
							        
									textmotorOil.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
										
							            public void onItemSelected(AdapterView<?> adapterView, 
							          	View view, int i, long l) { 
							          	// TODO Auto-generated method stub    	
							            	}
							            public void onNothingSelected(AdapterView<?> arg0) {
											// TODO Auto-generated method stub
							            	InputMethodManager imm = (InputMethodManager) getSystemService(
							                        INPUT_METHOD_SERVICE);
							                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
										} 
					
						      });

									textmotorOil.setOnItemClickListener(new  OnItemClickListener(){
											@Override
											public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
												// TODO Auto-generated method stub
												
												
								            	
								            	String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201309160001' and ItemName = '"+arg0.getItemAtPosition(position).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
														//et1.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list1 = rs.getString("ItemName")+",";
										                //price1 = rs.getString("LastBuyPrice")+",";
										            	t1 = Integer.parseInt(rs.getString("Duration"));
										            	str1 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}    
								            	
								            	 Toast.makeText(HoleActivity.this,"list1 = "+list1, Toast.LENGTH_SHORT).show();
												 
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+position+" Month:"+arg0.getItemAtPosition(position));
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountOne);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountOne.get(i));
											            	double ans = div * Double.parseDouble(str1);
											            	
											            	et1.setText(df.format(ans));
											                price1 = String.valueOf(ans)+",";
											            	a = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											}

							            });
									
									
				}
	    			else {
	    				 a = 0;
	    				 t1 = 0;
	    				 price.clear();
					     name.clear();
					     textmotorOil.setEnabled(false);
					     textmotorOil.setText("");
	    				 et1.setText("");
	    				 list1 = "";
	    				 price1 = "";
	    				 spn.setEnabled(false);
	    				}
	            }
	        });	
				
				
			
		}	

	private void GearOil() {
		final Spinner spn = (Spinner) findViewById(R.id.spin2);
		 spn.setEnabled(false);
		 c2 = ( CheckBox ) this.findViewById ( R.id.check2);			
		 et2 = ( TextView ) this.findViewById ( R.id.result2);
		
			
			c2.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c2.isChecked()){
	    				 spn.setEnabled(true);
	    				textGearOil.setEnabled(true);
						 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201309160002' ");		   

									try {
										while(rs.next()){          
											Gearprice.add(rs.getString("LastBuyPrice"));	
											Gearname.add(rs.getString("ItemName"));	
											Geartime.add(rs.getString("Duration"));
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}    
									for(int i = 1 ; i<=10 ; i++){
										amountGear.add(String.valueOf(i));
										}
									
									
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, Gearname);
									textGearOil.setThreshold(1);
							         
									textGearOil.setAdapter(adapter);
									
							        
									textGearOil.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
										
							            public void onItemSelected(AdapterView<?> adapterView, 
							          	View view, int i, long l) { 
							          	// TODO Auto-generated method stub    	
							            	}
							            public void onNothingSelected(AdapterView<?> arg0) {
											// TODO Auto-generated method stub
							            	InputMethodManager imm = (InputMethodManager) getSystemService(
							                        INPUT_METHOD_SERVICE);
							                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
										} 
					
						      });

									textGearOil.setOnItemClickListener(new  OnItemClickListener(){
											@Override
											public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
												// TODO Auto-generated method stub
												
												String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201309160002' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
														//et2.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list2 = rs.getString("ItemName")+",";
										            	//price2 = rs.getString("LastBuyPrice")+",";
										            	t2 = Integer.parseInt(rs.getString("Duration"));
										            	str2 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}    	
								            	 Toast.makeText(HoleActivity.this,"list2 = "+list2, Toast.LENGTH_SHORT).show();
												 
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+i+" Month:"+arg0.getItemAtPosition(i));
												
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountGear);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountGear.get(i));
											            	double ans = div * Double.parseDouble(str2);
											            	
											            	et2.setText(df.format(ans));
											                price2 = String.valueOf(ans)+",";
											            	b = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											
											}

							            });
	
	    			}
	    			else {
	    				 b = 0;
	    				 t2 = 0;
	    				 Gearprice.clear();
					     Gearname.clear();
					     textGearOil.setEnabled(false);
					     textGearOil.setText("");
	    				 et2.setText("");
	    				 list2 = "";
	    				 price2 = "";
	    				 spn.setEnabled(false);
	    				}
	            }
	        });	
				
				
			
		}	 

	private void SprocketsOil() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin3);
		 spn.setEnabled(false);
		
		 c3 = ( CheckBox ) this.findViewById ( R.id.check3);			
		 et3 = ( TextView ) this.findViewById ( R.id.result3);
		
			c3.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c3.isChecked()){
	    				spn.setEnabled(true);
	    				textSprocketsOil.setEnabled(true);
						 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110001' ");		   
									try {
										while(rs.next()){          
											Sprocketsprice.add(rs.getString("LastBuyPrice"));	
											Sprocketsname.add(rs.getString("ItemName"));	
											Sprocketstime.add(rs.getString("Duration"));
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}      
									
									for(int i = 1 ; i<=10 ; i++){
										amountSprockets.add(String.valueOf(i));
										}
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, Sprocketsname);
									textSprocketsOil.setThreshold(1);
							         
									textSprocketsOil.setAdapter(adapter);
							        
									textSprocketsOil.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
										
							            public void onItemSelected(AdapterView<?> adapterView, 
							          	View view, int i, long l) { 
							          	// TODO Auto-generated method stub    	
							            	}
							            public void onNothingSelected(AdapterView<?> arg0) {
											// TODO Auto-generated method stub
							            	InputMethodManager imm = (InputMethodManager) getSystemService(
							                        INPUT_METHOD_SERVICE);
							                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
										} 
					
						      });

									textSprocketsOil.setOnItemClickListener(new  OnItemClickListener(){
											@Override
											public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
												// TODO Auto-generated method stub
												
												String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110001' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
														//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list3 = rs.getString("ItemName")+",";
										            	//price3 = rs.getString("LastBuyPrice")+",";
										            	t3 = Integer.parseInt(rs.getString("Duration"));
										            	str3 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}    	
												 
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+i+" Month:"+arg0.getItemAtPosition(i));
												
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountSprockets);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountSprockets.get(i));
											            	double ans = div * Double.parseDouble(str3);
											            	
											            	et3.setText(df.format(ans));
											                price3 = String.valueOf(ans)+",";
											            	c = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											
											}

							            });
	
	    			}
	    			else {
	    				amountSprockets.clear();
	    				c = 0;
	    				t3 = 0;
	    				Sprocketsprice.clear();
						 Sprocketsname.clear();
						 textSprocketsOil.setEnabled(false);
						 textSprocketsOil.setText("");
	    				et3.setText("");
	    				list3 = "";
	    				price3 = "";
	    				spn.setEnabled(false);
	    				}
	            }
	        });	
				
				
			
		}	

	@SuppressLint("NewApi")
	private void GearOilAuto() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin4);
		 spn.setEnabled(false);
	
		// textGearOilAuto
		 c4 = ( CheckBox ) this.findViewById ( R.id.check4);			
		 et4 = ( TextView ) this.findViewById ( R.id.result4);
		 
		 c4.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c4.isChecked()){
	    				spn.setEnabled(true);
	    				textGearOilAuto.setEnabled(true);

	    				 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110012' ");		   
							try {
								while(rs.next()){          
									GearOilAutoprice.add(rs.getString("LastBuyPrice"));	
									GearOilAutoname.add(rs.getString("ItemName"));	
									GearOilAutotime.add(rs.getString("Duration"));
									}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      

						for(int i = 1 ; i<=10 ; i++){
						amountGearOilAuto.add(String.valueOf(i));
						}
						
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, GearOilAutoname);
						textGearOilAuto.setThreshold(1);
						textGearOilAuto.setAdapter(adapter);
						textGearOilAuto.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub    	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub
				            	InputMethodManager imm = (InputMethodManager) getSystemService(
				                        INPUT_METHOD_SERVICE);
				                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
							} 
		
			      });
						textGearOilAuto.setOnItemClickListener(new  OnItemClickListener(){
							@Override
							public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
								// TODO Auto-generated method stub
								
								String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110012' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
				            	ResultSet rs = con.selectData(sql);
				            	try {
									while(rs.next()){   
										//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
						            	list4 = rs.getString("ItemName")+",";
						            	//price3 = rs.getString("LastBuyPrice")+",";
						            	t4 = Integer.parseInt(rs.getString("Duration"));
						            	str = rs.getString("LastBuyPrice");
										}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    	
				            	
						ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountGearOilAuto);
						empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
						spn.setAdapter(empolyeeAdapter);
			
						spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub
				            	double div = Double.parseDouble(amountGearOilAuto.get(i));
				            	double ans = div * Double.parseDouble(str);
				            	
				            	et4.setText(df.format(ans));
				                price4 = String.valueOf(ans)+",";
				            	d = ans;
				            	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub

							} 
							
					      });
						
						}

		            });

}
	    			else {
	    					d = 0;
		    				t4 = 0;
		    				GearOilAutoprice.clear();
		    				GearOilAutoname.clear();
						    textGearOilAuto.setEnabled(false);
						    textGearOilAuto.setText("");
		    				et4.setText("");
		    				list4 = "";
		    				price4 = "";
		    				spn.setEnabled(false);
		
	    				}
	            }
	        });


			
		}	
	
	
	
	
	@SuppressLint("NewApi")
	private void SteeringWheel() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin5);
		 spn.setEnabled(false);
	
		// textGearOilAuto
		 c5 = ( CheckBox ) this.findViewById ( R.id.check5);			
		 et5 = ( TextView ) this.findViewById ( R.id.result5);
		 
		 c5.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c5.isChecked()){
	    				spn.setEnabled(true);
	    				textSteeringWheel.setEnabled(true);

	    				 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110013' ");		   
							try {
								while(rs.next()){          
									SteeringWheelprice.add(rs.getString("LastBuyPrice"));	
									SteeringWheelname.add(rs.getString("ItemName"));	
									SteeringWheeltime.add(rs.getString("Duration"));
									}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      

						for(int i = 1 ; i<=10 ; i++){
							amountSteeringWheel.add(String.valueOf(i));
						}
						
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, SteeringWheelname);
					textSteeringWheel.setThreshold(1);
					textSteeringWheel.setAdapter(adapter);
					textSteeringWheel.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub    	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub
				            	InputMethodManager imm = (InputMethodManager) getSystemService(
				                        INPUT_METHOD_SERVICE);
				                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
							} 
		
			      });
					textSteeringWheel.setOnItemClickListener(new  OnItemClickListener(){
							@Override
							public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
								// TODO Auto-generated method stub
								
								String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110013' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
				            	ResultSet rs = con.selectData(sql);
				            	try {
									while(rs.next()){   
										//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
						            	list5 = rs.getString("ItemName")+",";
						            	//price3 = rs.getString("LastBuyPrice")+",";
						            	t5 = Integer.parseInt(rs.getString("Duration"));
						            	str = rs.getString("LastBuyPrice");
										}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    	
				            	
						ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountSteeringWheel);
						empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
						spn.setAdapter(empolyeeAdapter);
			
						spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub
				            	double div = Double.parseDouble(amountSteeringWheel.get(i));
				            	double ans = div * Double.parseDouble(str);
				            	
				            	et5.setText(df.format(ans));
				                price5 = String.valueOf(ans)+",";
				            	e = ans;
				            	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub

							} 
							
					      });
						
						}

		            });

}
	    			else {
	    					e = 0;
		    				t5 = 0;
		    				SteeringWheelprice.clear();
		    				SteeringWheelname.clear();
		    				textSteeringWheel.setEnabled(false);
						    textSteeringWheel.setText("");
						    amountSteeringWheel.clear();
		    				et5.setText("");
		    				list5 = "";
		    				price5 = "";
		    				spn.setEnabled(false);
		
	    				}
	            }
	        });


			
		}	
	
	
	
	@SuppressLint("NewApi")
	private void within() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin6);
		 spn.setEnabled(false);
	
		// textGearOilAuto
		 c6 = ( CheckBox ) this.findViewById ( R.id.check6);			
		 et6 = ( TextView ) this.findViewById ( R.id.result6);
		 
		 c6.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c6.isChecked()){
	    				spn.setEnabled(true);
	    				textwithin.setEnabled(true);

	    				 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110014' ");		   
							try {
								while(rs.next()){          
									withinprice.add(rs.getString("LastBuyPrice"));	
									withinname.add(rs.getString("ItemName"));	
									withintime.add(rs.getString("Duration"));
									}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      

						for(int i = 1 ; i<=10 ; i++){
							amountwithin.add(String.valueOf(i));
						}
						
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, withinname);
					textwithin.setThreshold(1);
					textwithin.setAdapter(adapter);
					textwithin.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub    	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub
				            	InputMethodManager imm = (InputMethodManager) getSystemService(
				                        INPUT_METHOD_SERVICE);
				                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
							} 
		
			      });
					textwithin.setOnItemClickListener(new  OnItemClickListener(){
							@Override
							public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
								// TODO Auto-generated method stub
								
								String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110014' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
				            	ResultSet rs = con.selectData(sql);
				            	try {
									while(rs.next()){   
										//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
						            	list6 = rs.getString("ItemName")+",";
						            	//price3 = rs.getString("LastBuyPrice")+",";
						            	t6 = Integer.parseInt(rs.getString("Duration"));
						            	str = rs.getString("LastBuyPrice");
										}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    	
				            	
						ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountwithin);
						empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
						spn.setAdapter(empolyeeAdapter);
			
						spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub
				            	double div = Double.parseDouble(amountwithin.get(i));
				            	double ans = div * Double.parseDouble(str);
				            	
				            	et6.setText(df.format(ans));
				                price6 = String.valueOf(ans)+",";
				            	f = ans;
				            	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub

							} 
							
					      });
						
						}

		            });

}
	    			else {
	    					f = 0;
		    				t6 = 0;
		    				withinprice.clear();
		    				withinname.clear();
		    				textwithin.setEnabled(false);
						    textwithin.setText("");
						    amountwithin.clear();
		    				et6.setText("");
		    				list6 = "";
		    				price6 = "";
		    				spn.setEnabled(false);
		
	    				}
	            }
	        });


			
		}	
	
	
	@SuppressLint("NewApi")
	private void boiler() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin7);
		 spn.setEnabled(false);
	
		// textGearOilAuto
		 c7 = ( CheckBox ) this.findViewById ( R.id.check7);			
		 et7 = ( TextView ) this.findViewById ( R.id.result7);
		 
		 c7.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c7.isChecked()){
	    				spn.setEnabled(true);
	    				textboiler.setEnabled(true);

	    				 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110015' ");		   
							try {
								while(rs.next()){          
									boilerprice.add(rs.getString("LastBuyPrice"));	
									boilername.add(rs.getString("ItemName"));	
									boilertime.add(rs.getString("Duration"));
									}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      

						for(int i = 1 ; i<=10 ; i++){
							amountboiler.add(String.valueOf(i));
						}
						
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, boilername);
					    textboiler.setThreshold(1);
					    textboiler.setAdapter(adapter);
					    textboiler.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub    	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub
				            	InputMethodManager imm = (InputMethodManager) getSystemService(
				                        INPUT_METHOD_SERVICE);
				                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
							} 
		
			      });
					textboiler.setOnItemClickListener(new  OnItemClickListener(){
							@Override
							public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
								// TODO Auto-generated method stub
								
								String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110015' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
				            	ResultSet rs = con.selectData(sql);
				            	try {
									while(rs.next()){   
										//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
						            	list7 = rs.getString("ItemName")+",";
						            	//price3 = rs.getString("LastBuyPrice")+",";
						            	t7 = Integer.parseInt(rs.getString("Duration"));
						            	str = rs.getString("LastBuyPrice");
										}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    	
				            	
						ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountboiler);
						empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
						spn.setAdapter(empolyeeAdapter);
			
						spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub
				            	double div = Double.parseDouble(amountboiler.get(i));
				            	double ans = div * Double.parseDouble(str);
				            	
				            	et7.setText(df.format(ans));
				                price7 = String.valueOf(ans)+",";
				            	g = ans;
				            	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub

							} 
							
					      });
						
						}

		            });

}
	    			else {
	    					g = 0;
		    				t7 = 0;
		    				boilerprice.clear();
		    				boilername.clear();
		    				textboiler.setEnabled(false);
						    textboiler.setText("");
						    amountboiler.clear();
		    				et7.setText("");
		    				list7 = "";
		    				price7 = "";
		    				spn.setEnabled(false);
		
	    				}
	            }
	        });


			
		}	
	
	
	
	private void grease() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin8);
		 spn.setEnabled(false);
		 	
		 c8 = ( CheckBox ) this.findViewById ( R.id.check8);			
		 et8 = ( TextView ) this.findViewById ( R.id.result8);
		 
		 c8.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c8.isChecked()){
	    				
	    				spn.setEnabled(true);
			
	    				 rs = con.selectData("SELECT * FROM Item WHERE OID = '104201310110005' ");	
						try {

							    rs.next();
							    str = rs.getString("LastBuyPrice");
							    list8 = rs.getString("ItemName")+",";
							   // price8 = rs.getString("LastBuyPrice")+",";
							    t8 = Integer.parseInt(rs.getString("Duration").toString());
		
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}  
						for(int i = 1 ; i<=10 ; i++){
							amountgrease.add(String.valueOf(i));
							}
							
							ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountgrease);
							empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
							spn.setAdapter(empolyeeAdapter);
							
							spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
								
					            public void onItemSelected(AdapterView<?> adapterView, 
					          	View view, int i, long l) { 
					          	// TODO Auto-generated method stub
					            	double div = Double.parseDouble(amountgrease.get(i));
					            	double ans = div * Double.parseDouble(str);

										et8.setText(df.format(ans));
										price8 = String.valueOf(ans)+",";
										h = ans;
					            	}
					            public void onNothingSelected(AdapterView<?> arg0) {
									// TODO Auto-generated method stub

								} 
			
				      });
					   
					
	    				}
	    			else {
	    				t8 = 0;
	    				 h = 0;
	    				 et8.setText("");  
	    				 list8 = "";
	    				 price8 = "";
	    				 spn.setEnabled(false);
	    				 amountgrease.clear();
	    				}
	            }
	        });


			
		}	
	
	
	private void brake() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin9);
		 spn.setEnabled(false);
		
		 c9 = ( CheckBox ) this.findViewById ( R.id.check9);			
		 et9 = ( TextView ) this.findViewById ( R.id.result9);
	
			c9.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c9.isChecked()){
	    				 spn.setEnabled(true);
	    				textbrake.setEnabled(true);
						 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201309160003' ");		   

									try {
										while(rs.next()){          
											Brakesprice.add(rs.getString("LastBuyPrice"));	
											Brakesname.add(rs.getString("ItemName"));	
											Brakestime.add(rs.getString("Duration"));
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									} 
									
									for(int i = 1 ; i<=10 ; i++){
										amountBrakes.add(String.valueOf(i));
										}
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, Brakesname);
									textbrake.setThreshold(1);
							         
									textbrake.setAdapter(adapter);
							         
									textbrake.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
											
								            public void onItemSelected(AdapterView<?> adapterView, 
								          	View view, int i, long l) { 
								          	// TODO Auto-generated method stub    	
								            	}
								            public void onNothingSelected(AdapterView<?> arg0) {
												// TODO Auto-generated method stub
								            	InputMethodManager imm = (InputMethodManager) getSystemService(
								                        INPUT_METHOD_SERVICE);
								                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
											} 
						
							      });
									textbrake.setOnItemClickListener(new  OnItemClickListener(){

											@Override
											public void onItemClick(
													AdapterView<?> arg0,
													View arg1, int i,
													long arg3) {
												// TODO Auto-generated method stub
												
												String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201309160003' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
													//	et9.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list9 = rs.getString("ItemName")+",";
										            	//price9 = rs.getString("LastBuyPrice")+",";
										            	t9 = Integer.parseInt(rs.getString("Duration"));
										            	str9 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												} 
												 
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+i+" Month:"+arg0.getItemAtPosition(i));
												
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountBrakes);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountBrakes.get(i));
											            	double ans = div * Double.parseDouble(str9);
											            	
											            	et9.setText(df.format(ans));
											                price9 = String.valueOf(ans)+",";
											            	ii = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											
											}

										
							            	
							            });
							
	    			}
	    			else {
	    			     ii = 0;
	    			     t9 = 0;
	    				 Brakesprice.clear();
						 Brakesname.clear();
						 textbrake.setEnabled(false);
						 textbrake.setText("");
	    				 et9.setText("");
	    				 list9 = "";
	    				 price9 = "";
	    				 spn.setEnabled(false);
	    				 
	    				}
	            }
	        });	
				
				
			
		}	 
	
	private void filter() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin10);
		 spn.setEnabled(false);
		
		 c10 = ( CheckBox ) this.findViewById ( R.id.check10);			
		 et10 = ( TextView ) this.findViewById ( R.id.result10);
		 
			
			c10.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c10.isChecked()){
	    				 spn.setEnabled(true);
	    				textfilter.setEnabled(true);
						 rs = con.selectData("SELECT *,ItemCode+' '+ItemName AS ItemCo FROM Item WHERE ItemGroupCode = '105201309160011' ");		   

									try {
										while(rs.next()){          
											filterprice.add(rs.getString("LastBuyPrice"));	
											filtername.add(rs.getString("ItemCo"));	
											filtertime.add(rs.getString("Duration"));
		
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}   
									
									for(int i = 1 ; i<=10 ; i++){
										amountfilter.add(String.valueOf(i));
										}
									
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, filtername);
									textfilter.setThreshold(1);
							         
									textfilter.setAdapter(adapter);
							         
									textfilter.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
											
								            public void onItemSelected(AdapterView<?> adapterView, 
								          	View view, int i, long l) { 
								          	// TODO Auto-generated method stub    	
								            	}
								            public void onNothingSelected(AdapterView<?> arg0) {
												// TODO Auto-generated method stub
								            	InputMethodManager imm = (InputMethodManager) getSystemService(
								                        INPUT_METHOD_SERVICE);
								                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
											} 
						
							      });
									textfilter.setOnItemClickListener(new  OnItemClickListener(){

											@Override
											public void onItemClick(
													AdapterView<?> arg0,
													View arg1, int i,
													long arg3) {
												// TODO Auto-generated method stub
												
												String sql = "SELECT *,ItemCode+' '+ItemName AS ItemCo FROM Item WHERE ItemGroupCode = '105201309160011' and ItemCode+' '+ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
														//et10.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list10 = rs.getString("ItemCo")+",";
										            //	price10 = rs.getString("LastBuyPrice")+",";
										            	t10 = Integer.parseInt(rs.getString("Duration"));
										            	str10 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												} 
								            	
								            	
								            	 Toast.makeText(HoleActivity.this,"list10 = "+list10, Toast.LENGTH_SHORT).show();
								            	 Toast.makeText(HoleActivity.this,"list10_2 = "+filtername.get(i).toString(), Toast.LENGTH_SHORT).show();
								            	
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+i+" Month:"+arg0.getItemAtPosition(i));
												
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountfilter);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountfilter.get(i));
											            	double ans = div * Double.parseDouble(str10);
											            	
											            	et10.setText(df.format(ans));
											                price10 = String.valueOf(ans)+",";
											            	j = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											
											}

										
							            	
							            });
		
	    			}
	    			else {
	    				t10 = 0;
	    				j = 0;
	    				filterprice.clear();
	    				filtername.clear();
	    				textfilter.setEnabled(false);
	    				textfilter.setText("");
	    				et10.setText("");
	    				 list10 = "";
	    				 price10 = "";
	    				 spn.setEnabled(false);
	    				}
	            }
	        });	
				
				
			
		}	 
	
	
private void filterAir() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin11);
		 spn.setEnabled(false);
		
		 c11 = ( CheckBox ) this.findViewById ( R.id.check11);			
		 et11 = ( TextView ) this.findViewById ( R.id.result11);
		 
			
			c11.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c11.isChecked()){
	    				 spn.setEnabled(true);
	    				textfilterAir.setEnabled(true);
						 rs = con.selectData("SELECT *,ItemCode+' '+ItemName AS ItemCo FROM Item WHERE ItemGroupCode = '105201309160008' ");		   

									try {
										while(rs.next()){          
											filterAirprice.add(rs.getString("LastBuyPrice"));	
											filterAirname.add(rs.getString("ItemCo"));	
											filterAirtime.add(rs.getString("Duration"));
		
											}
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}   
									
									for(int i = 1 ; i<=10 ; i++){
										amountfilterAir.add(String.valueOf(i));
										}
									
									ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, filterAirname);
									textfilterAir.setThreshold(1);
							         
									textfilterAir.setAdapter(adapter);
							         
									textfilterAir.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
											
								            public void onItemSelected(AdapterView<?> adapterView, 
								          	View view, int i, long l) { 
								          	// TODO Auto-generated method stub    	
								            	}
								            public void onNothingSelected(AdapterView<?> arg0) {
												// TODO Auto-generated method stub
								            	InputMethodManager imm = (InputMethodManager) getSystemService(
								                        INPUT_METHOD_SERVICE);
								                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
											} 
						
							      });
									textfilterAir.setOnItemClickListener(new  OnItemClickListener(){

											@Override
											public void onItemClick(
													AdapterView<?> arg0,
													View arg1, int i,
													long arg3) {
												// TODO Auto-generated method stub
												
												String sql = "SELECT *,ItemCode+' '+ItemName AS ItemCo FROM Item WHERE ItemGroupCode = '105201309160008' and ItemCode+' '+ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
								            	ResultSet rs = con.selectData(sql);
								            	try {
													while(rs.next()){   
														//et10.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
										            	list11 = rs.getString("ItemCo")+",";
										            //	price10 = rs.getString("LastBuyPrice")+",";
										            	t11 = Integer.parseInt(rs.getString("Duration"));
										            	str11 = rs.getString("LastBuyPrice");
														}
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												} 
								            	
								            	
								            	 Toast.makeText(HoleActivity.this,"list11 = "+list11, Toast.LENGTH_SHORT).show();
								            	 Toast.makeText(HoleActivity.this,"list11_2 = "+filterAirname.get(i).toString(), Toast.LENGTH_SHORT).show();
								            	
								            	  Toast.makeText(HoleActivity.this,arg0.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
												 Log.i("AutocompleteContacts", "Position:"+i+" Month:"+arg0.getItemAtPosition(i));
												
												 ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountfilterAir);
													empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
													spn.setAdapter(empolyeeAdapter);
													
													spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
														
											            public void onItemSelected(AdapterView<?> adapterView, 
											          	View view, int i, long l) { 
											          	// TODO Auto-generated method stub
											            	double div = Double.parseDouble(amountfilterAir.get(i));
											            	double ans = div * Double.parseDouble(str11);
											            	
											            	et11.setText(df.format(ans));
											                price11 = String.valueOf(ans)+",";
											            	k = ans;
											            	
											            	}
											            public void onNothingSelected(AdapterView<?> arg0) {
															// TODO Auto-generated method stub

														} 
									
										      });
											
											}

										
							            	
							            });
		
	    			}
	    			else {
	    				t11 = 0;
	    				k = 0;
	    				filterAirprice.clear();
	    				filterAirname.clear();
	    				textfilterAir.setEnabled(false);
	    				textfilter.setText("");
	    				et11.setText("");
	    				 list11 = "";
	    				 price11 = "";
	    				 spn.setEnabled(false);
	    				}
	            }
	        });	
				
				
			
		}	 
	
	
	
	
	@SuppressLint("NewApi")
	private void liquor() {
		
		 final Spinner spn = (Spinner) findViewById(R.id.spin12);
		 spn.setEnabled(false);
	
		// textGearOilAuto
		 c12 = ( CheckBox ) this.findViewById ( R.id.check12);			
		 et12 = ( TextView ) this.findViewById ( R.id.result12);
		 
		 c12.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c12.isChecked()){
	    				
	    				spn.setEnabled(true);
	    				textliquor.setEnabled(true);

	    				 rs = con.selectData("SELECT * FROM Item WHERE ItemGroupCode = '105201310110016' ");		   
							try {
								while(rs.next()){          
									liquorprice.add(rs.getString("LastBuyPrice"));	
									liquorname.add(rs.getString("ItemName"));	
									liquortime.add(rs.getString("Duration"));
									}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      

						for(int i = 1 ; i<=10 ; i++){
							amountliquor.add(String.valueOf(i));
						}
						
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(HoleActivity.this, android.R.layout.simple_dropdown_item_1line, liquorname);
					    textliquor.setThreshold(1);
					    textliquor.setAdapter(adapter);
					    textliquor.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long l) { 
				          	// TODO Auto-generated method stub    	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub
				            	InputMethodManager imm = (InputMethodManager) getSystemService(
				                        INPUT_METHOD_SERVICE);
				                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
							} 
		
			      });
					textliquor.setOnItemClickListener(new  OnItemClickListener(){
							@Override
							public void onItemClick(AdapterView<?> arg0, View arg1, int i, long arg3) {
								// TODO Auto-generated method stub
								
								String sql = "SELECT * FROM Item WHERE ItemGroupCode = '105201310110016' and ItemName = '"+arg0.getItemAtPosition(i).toString()+"'  ";
				            	ResultSet rs = con.selectData(sql);
				            	try {
									while(rs.next()){   
										//et3.setText(df.format(Double.parseDouble(rs.getString("LastBuyPrice"))));
						            	list12 = rs.getString("ItemName")+",";
						            	//price3 = rs.getString("LastBuyPrice")+",";
						            	t12 = Integer.parseInt(rs.getString("Duration"));
						            	str = rs.getString("LastBuyPrice");
										}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    	
				            	
						ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountliquor);
						empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
						spn.setAdapter(empolyeeAdapter);
			
						spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
							
				            public void onItemSelected(AdapterView<?> adapterView, 
				          	View view, int i, long ll) { 
				          	// TODO Auto-generated method stub
				            	double div = Double.parseDouble(amountliquor.get(i));
				            	double ans = div * Double.parseDouble(str);
				            	
				            	et12.setText(df.format(ans));
				                price12 = String.valueOf(ans)+",";
				            	l = ans;
				            	
				            	}
				            public void onNothingSelected(AdapterView<?> arg0) {
								// TODO Auto-generated method stub

							} 
							
					      });
						
						}

		            });

}
	    			else {
	    					l = 0;
		    				t12 = 0;
		    				liquorprice.clear();
		    				liquorname.clear();
		    				textliquor.setEnabled(false);
						    textliquor.setText("");
						    amountliquor.clear();
		    				et12.setText("");
		    				list12 = "";
		    				price12 = "";
		    				spn.setEnabled(false);
		
	    				}
	            }
	        });


			
		}	
	

	
	
	private void compress() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin13);
		 spn.setEnabled(false);
		
		 c13 = ( CheckBox ) this.findViewById ( R.id.check13);			
		 et13 = ( TextView ) this.findViewById ( R.id.result13);
		 
		 c13.setOnClickListener(new View.OnClickListener() {
				String str;
				@Override
				public void onClick(View v) {
	    			if(c13.isChecked()){
	    				
	    				 spn.setEnabled(true);
			
	    				 rs = con.selectData("SELECT * FROM Item WHERE OID = '104201310100002' ");	
						try {

							    rs.next();
							    str = rs.getString("LastBuyPrice");
							    list13 = rs.getString("ItemName")+",";
							   // price13 = rs.getString("LastBuyPrice")+",";
							    t13 = Integer.parseInt(rs.getString("Duration").toString());
		
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}  
						
						for(int i = 1 ; i<=10 ; i++){
							amountcompress.add(String.valueOf(i));
							}
							
							ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountcompress);
							empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
							spn.setAdapter(empolyeeAdapter);
							
							spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
								
					            public void onItemSelected(AdapterView<?> adapterView, 
					          	View view, int i, long l) { 
					          	// TODO Auto-generated method stub
					            	double div = Double.parseDouble(amountcompress.get(i));
					            	double ans = div * Double.parseDouble(str);

										et13.setText(df.format(ans));
										price13 = String.valueOf(ans)+",";
										m = ans;
					            	}
					            public void onNothingSelected(AdapterView<?> arg0) {
									// TODO Auto-generated method stub

								} 
			
				      });
						
				
	    				}
	    			else {
	    				t14 = 0;
	    				m = 0;
	    				et13.setText(""); 
	    				 list13 = "";
	    				 price13 = "";
	    				 spn.setEnabled(false);
	    				 amountcompress.clear();
	    				}
	            }
	        });
	} 
		 
	private void color() {
		
		final Spinner spn = (Spinner) findViewById(R.id.spin14);
		 spn.setEnabled(false);
		 
			 c14 = ( CheckBox ) this.findViewById ( R.id.check14);			
			 et14 = ( TextView ) this.findViewById ( R.id.result14);
			 
			 c14.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c14.isChecked()){
		    				
		    				spn.setEnabled(true);
				
		    				 rs = con.selectData("SELECT * FROM Item WHERE OID = '104201310110007' ");	
							try {

								    rs.next();
								    str = rs.getString("LastBuyPrice");
								    list14 = rs.getString("ItemName")+",";
								  //  price14 = rs.getString("LastBuyPrice")+",";
								    t14 = Integer.parseInt(rs.getString("Duration").toString());
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}  
							for(int i = 1 ; i<=10 ; i++){
								amountcolor.add(String.valueOf(i));
								}
								
								ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(HoleActivity.this,android.R.layout.simple_spinner_item,amountcolor);
								empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
								spn.setAdapter(empolyeeAdapter);
								
								spn.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 
									
						            public void onItemSelected(AdapterView<?> adapterView, 
						          	View view, int i, long l) { 
						          	// TODO Auto-generated method stub
						            	double div = Double.parseDouble(amountcolor.get(i));
						            	double ans = div * Double.parseDouble(str);

											et14.setText(df.format(ans));
											price14 = String.valueOf(ans)+",";
											n = ans;
						            	}
						            public void onNothingSelected(AdapterView<?> arg0) {
										// TODO Auto-generated method stub

									} 
				
					      });
							
							
					
		    				}
		    			else {
		    				t14 = 0;
		    				n = 0;
		    				et14.setText("");
		    				 list14 = "";
		    				 price14 = "";
		    				 spn.setEnabled(false);
		    				 amountcolor.clear();
		    				}
		            }
		        });
	}
	
	
	
	
	private void orther1() {

		 
		 c15 = ( CheckBox ) this.findViewById ( R.id.check15);	
		 
		 et15 = ( EditText ) this.findViewById ( R.id.result15);
		 et15.setEnabled(false);
		 
		 orther1 = ( EditText ) this.findViewById ( R.id.orther1);
		 orther1.setEnabled(false);
		 
		 c15.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c15.isChecked()){
	    				checkOrther1 = "checkOrther";
	    				orther1.setEnabled(true);
	    				et15.setEnabled(true);	
							
							
							
			
				
	    				}
	    			else {
	    				checkOrther1 = "";
	    				p = 0;
	    				orther1.setText("0");
	    				et15.setText("0");
	    				orther1.setEnabled(false);
	    				et15.setEnabled(false);
	    				}
	            }
	        });
}


	private void orther2() {

		 
		 c16 = ( CheckBox ) this.findViewById ( R.id.check16);	
		 
		 et16 = ( EditText ) this.findViewById ( R.id.result16);
		 et16.setEnabled(false);
		 
		 orther2 = ( EditText ) this.findViewById ( R.id.orther2);
		 orther2.setEnabled(false);
		 
		 c16.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	   			if(c16.isChecked()){
	   				checkOrther1 = "checkOrther";
	   				orther2.setEnabled(true);
	   				et16.setEnabled(true);	
							
							
							
			
				
	   				}
	   			else {
	   				checkOrther1 = "";
	   				q = 0;
	   				orther2.setText("0");
	   				et16.setText("0");
	   				orther2.setEnabled(false);
	   				et16.setEnabled(false);
	   				}
	           }
	       });
	}
	
private void orther3() {

	 
	 c17 = ( CheckBox ) this.findViewById ( R.id.check17);	
	 
	 et17 = ( EditText ) this.findViewById ( R.id.result17);
	 et17.setEnabled(false);
	 
	 orther3 = ( EditText ) this.findViewById ( R.id.orther3);
	 orther3.setEnabled(false);
	 
	 c17.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
			if(c17.isChecked()){
				checkOrther1 = "checkOrther";
				orther3.setEnabled(true);
				et17.setEnabled(true);	
						
						
						
		
			
				}
			else {
				checkOrther1 = "";
				r = 0;
				orther3.setText("0");
				et17.setText("0");
				orther3.setEnabled(false);
				et17.setEnabled(false);
				}
        }
    });
}


	
	
	@Override
	public void onBackPressed() {
	  
	        new AlertDialog.Builder(this)
	        .setTitle("¡��ԡ��÷���¡��")
	        .setMessage("��Ѻ�˹����ѡ")
	                .setNegativeButton(android.R.string.yes, new DialogInterface.OnClickListener() {

	                    public void onClick(DialogInterface arg0, int arg1) {
	                        Intent newActivity = new Intent(getApplicationContext(),MainActivity.class);	                          
	                        newActivity.putExtra("name", NameInput);
	                        newActivity.putExtra("CompanyS", company);
	                        startActivity(newActivity);
	                        finish();
	                        overridePendingTransition(R.layout.fadeendout,R.layout.fadeendin);
	                    }
	                })
	                .setPositiveButton(android.R.string.no, null).create().show();
	    

	}
	
	
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		Log.i("Get data", requestCode+"");
	
		switch (requestCode) {
		case services.REQUEST_CODE:
			 
			final AlertDialog.Builder dDialog = new AlertDialog.Builder(this);
			
			timeSer = data.getStringExtra("time");
			sumSer = data.getStringExtra("Money");
			listSer = data.getStringExtra("list");
			priceSer = data.getStringExtra("price");
			

			arr = listSer.split(",");
			arr2 = priceSer.split(",");
			
			
			  Toast.makeText(HoleActivity.this, timeSer+" "+sumSer+" "+listSer+" "+priceSer, Toast.LENGTH_LONG).show();
			  

			  Sum.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						
						if(et15.getText().toString().equals("")){
							p = 0;
						}else{
						p = Double.parseDouble(et15.getText().toString());
						}
						
						if(et16.getText().toString().equals("")){
							q = 0;
						}else{
						q = Double.parseDouble(et16.getText().toString());
						}
						
						if(et17.getText().toString().equals("")){
							r = 0;
						}else{
						r = Double.parseDouble(et17.getText().toString());
						}
						
						
						
						///////////  ��ǹ ����� ////////////
						
						if(et15.getText().toString().equals("")){
							p = 0;
						}else{
						p = Double.parseDouble(et15.getText().toString());
						}
						
						if(et16.getText().toString().equals("")){
							q = 0;
						}else{
						q = Double.parseDouble(et16.getText().toString());
						}
						
						if(et17.getText().toString().equals("")){
							r = 0;
						}else{
						r = Double.parseDouble(et17.getText().toString());
						}
						
						
								//////////////  ��ǹŴ�ٻͧ	
									sumDiscNull = disc.getText().toString();
				    				
				    				if(sumDiscNull.equals(null)||sumDiscNull.equals("")){
				    					sumDisc = "0";
				    				}else{
				    					sumDisc = sumDiscNull;
				    				}
				    				sumDisBTHNull = disBTH.getText().toString();
				    				
				    				if(sumDisBTHNull.equals(null)||sumDisBTHNull.equals("")){
				    					sumDisBTH = "0";
				    				}else{
				    					
				    					sumDisBTH = sumDisBTHNull;
				    				}
				    				
				    			////////////////���ǹŴ VIP
				    				VIPcode = prom.getText().toString();
				    				
				    				
				    				
						
						timeSum = t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+Integer.parseInt(timeSer);
						timeSum = timeSum+0;
						Toast.makeText(HoleActivity.this, "All time is : "+timeSum, Toast.LENGTH_SHORT).show();
						
						amount = a+b+c+d+e+f+g+h+ii+j+k+l+m+n+o+p+q+r+Double.parseDouble(sumSer);
						SumAmount.setText(String.valueOf(df.format(amount)));
						
						finalSum = (amount-Integer.parseInt(sumDisBTH))-(((amount-Integer.parseInt(sumDisBTH))*Integer.parseInt(sumDisc))/100);
						

						TextSum.setText(String.valueOf(df.format(finalSum)));	


					}
					});
			  
			  btn1.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						
			
						rs2 = con.selectData("SELECT MAX(ServiceID) AS maxid FROM CustomerCar WHERE RegisterID = '"+RegisterIDS+"' ");
	   				try {
	   					rs2.next();
	   					ServiceID = rs2.getString("maxid");
	   				} catch (SQLException e1) {
	   					// TODO Auto-generated catch block
	   					e1.printStackTrace();
	   				}
	   				
	   				
	   				
	   				if(et15.getText().toString().equals("")){
	   					price15 = "-,";
		   				list15 = "-,";
					}else{
						price15 = et15.getText().toString()+",";
		   				list15 = orther1.getText().toString()+",";
					}
					
					if(et16.getText().toString().equals("")){
						price16 = "-,";
		   				list16 = "-,";
					}else{
						price16 = et16.getText().toString()+",";
		   				list16 = orther2.getText().toString()+",";
					}
					
					if(et17.getText().toString().equals("")){
						price17 = "-,";
		   				list17 = "-,";
					}else{
						price17 = et17.getText().toString()+",";
		   				list17 = orther3.getText().toString()+",";
					}
	   				
					
					
						 
						String sql = "INSERT INTO DataService " +
								"(ServiceID,TypeID,List,price,VIPcode,Discount,amount,Sum,sumTime,date" +
											",DiscountName,PriceBTH,checkOrther) " +
								"VALUES ("+
								"'"+ServiceID+"'" + ',' + 
								"'"+TypeID+"'" + ',' + 
								"'"+list1+list2+list3+list4+list5+list6+list7+list8+list9+
								list10+list11+list12+list13+list14+listSer+list15+list16+list17+"'" + ',' + 
								"'"+price1+price2+price3+price4+price5+price6+price7+price8+price9+
								price10+price11+price12+price13+price14+priceSer+price15+price16+price17+"'" + ',' + 
								"'"+VIPcode+"'" + ',' +
											"'"+sumDisc+"'" + ',' +
											"'"+amount+"'" + ',' +
											"'"+finalSum+"'" + ',' +
											"'"+timeSum+"'" + ',' +
									        "'"+mDay+"/"+(1+mMonth)+"/"+mYear+"'" + "," +
									        "'"+DisCt+"'" + ',' +
									        "'"+sumDisBTH+"'" + ',' +
											"'"+checkOrther1+"'" + ") "; 
	   				
	   				
						
					if(con.addData(sql)){	 
					Toast.makeText(HoleActivity.this, "Inserted data successfully", Toast.LENGTH_SHORT).show();
					Toast.makeText(HoleActivity.this, ServiceID, Toast.LENGTH_SHORT).show();
					Intent newActivityAdd = new Intent(HoleActivity.this,Card.class);
					newActivityAdd.putExtra("ServiceID", ServiceID);
					newActivityAdd.putExtra("name", NameInput);
					newActivityAdd.putExtra("CompanyS", company);
					startActivity(newActivityAdd);
					
					}else{
				    Toast.makeText(HoleActivity.this, "Inserted data fail", Toast.LENGTH_SHORT).show();
				  
					}
					
					}
					
			 });
			 
		}
	}
	
	public void selectDis(){
		
		//	String tusTmp = getIntent().getExtras().getString("Status");	
			  spnDis = (Spinner) findViewById(R.id.selectDiscount);
			
			
			
			
			Dis.add("��س����͡");
			Dis.add("����");
			Dis.add("�.�.�.");
			Dis.add("��ǹŴ˹���ҹ");
				
			
			
		ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Dis);
		empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
		spnDis.setAdapter(empolyeeAdapter);

		spnDis.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 

		public void onItemSelected(AdapterView<?> adapterView, 
			View view, int i, long l) { 
			// TODO Auto-generated method stub
			
			
			DisCt = Dis.get(i);
			
			
			
			}
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			Toast.makeText(HoleActivity.this,
						String.valueOf("ʶҹ��ա������¹�ŧ����"),
							Toast.LENGTH_SHORT).show();
		} 

		});
		
		}		  

	
@Override


	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
